package com.yunxi.poc.starbucks.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunxi.poc.starbucks.entity.Order;
import com.yunxi.poc.starbucks.mapper.OrderMapper;
import com.yunxi.poc.starbucks.service.IOrderService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author shiyuan.xlc
 * @since 2021-08-12
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {

    @Override
    public Order getLatestMakeFinishOrder(LocalDateTime compareTo, String storeId) {
        QueryWrapper<Order> queryWrapperOrder = new QueryWrapper<>();
        queryWrapperOrder.eq("store_id", storeId);
        queryWrapperOrder.lt("make_finish_date", compareTo);
        queryWrapperOrder.orderByDesc("make_finish_date");
        queryWrapperOrder.last("limit 1");
        return this.getOne(queryWrapperOrder);
    }
}
